<?php
declare(strict_types=1);
namespace Dao;
// hook dao_auth_taobao_cate_use.php

use Model\AuthTaobaoCateModel;
use Swoole\Timer;

class AuthTaobaoCateDao extends AuthTaobaoCateModel
{
	// hook dao_auth_taobao_cate_public_start.php

	protected array $add_rule	=	[];
    protected array $edit_rule	=	[];

    protected array $rule	=	[
		/*
		"mobile"=>[
			"max"=>3
			"min"=>3
			"func"=>'isMobile'
			"error"=>false,
			'message'=>'格式有误'
		],
		"username"=>[
			"max"=>3
			"min"=>3
			"func"=>'checkS'
			"error"=>false,
			'message'=>'格式有误'
		],
		*/
	];
	//数据，字段，验证规则
	/*
	function isMobile($data,$field,$val){
	
		return true;
	}
	*/
	
	// hook dao_auth_taobao_cate_public_end.php

    public function auto_load()
    {
        // hook model_user_auto_load_start.php
        if ($this->http_server->worker_id == 1) {
            Timer::after(5000, function () {
                $this->reload();
            });
        }
    }

    public function reload($cond=[])
    {
        $data = $this->select($cond);
        if (!empty($data)) {
            foreach ($data as $row) {
                    $this->T_AuthTaobaoCate->set($row['TbID'].'',[
                        'ParentTbID'=>$row['ParentTbID'],
                        'Name'=>$row['Name'],
                        'IsParent'=>$row['IsParent'],
                        'Lv'=>$row['Lv'],
                    ]);

            }
        }
    }
	// hook dao_auth_taobao_cate_end.php
}
?>